set more off

use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	
	merge 1:1 postcode contract_quarter using Data/sales_postcodequarter.dta
	
	keep if _merge ==3 
	drop _merge
	
	
		
	
	collapse (mean) Salesdriven DoortoDoor Othersales Telesalesunknown TelesalesOut TelesalesIn Consumerdriven Pricecomparison  Otherconnection Renewal, by(contract_quarter)
	
	
	twoway (connected Salesdriven contract_quarter, lcolor(gs9) msymbol(+) msize(small) mcolor(gs0) lpattern(solid)) (connected Consumerdriven contract_quarter, lcolor(gs0) msymbol(o) msize(small) mcolor(gs9) lpattern(solid))  (connected Renewal contract_quarter, lcolor(gs0) msymbol(x) msize(small) mcolor(gs0) lpattern(dash)), legend(order(1 "Sales Driven" 2 "Customer Driven" 3 "Contract Renewal") region(lwidth(none)) rows(1)) xtitle("Quarter") ytitle("Share of New Contracts") 
	
	graph export Analysis/Postcodeshare_salestime.png, replace
	
	
	
	
	
	use Data/event_study_samplewithsolar_sales.dta, clear

	
	
 drop if ever_solar==1
 drop if has_solar ==1
 
 drop if Other ==1
 
 keep if moduleprice<. 
 
	collapse (sum) Salesdriven DoortoDoor Othersales Telesalesunknown TelesalesOut TelesalesIn Consumerdriven Pricecomparison  Otherconnection Renewal, by(contract_quarter)
	
	
	twoway (connected Salesdriven contract_quarter, lcolor(gs9) msymbol(+) msize(small) mcolor(gs0) lpattern(solid)) (connected Consumerdriven contract_quarter, lcolor(gs0) msymbol(o) msize(small) mcolor(gs9) lpattern(solid))  (connected Renewal contract_quarter, lcolor(gs0) msymbol(x) msize(small) mcolor(gs0) lpattern(dash)), legend(order(1 "Sales Driven" 2 "Customer Driven" 3 "Contract Renewal") region(lwidth(none)) rows(1)) xtitle("Quarter") ytitle("New Contracts") 	
	
	graph export Analysis/Aggregate_salestime.png, replace
